<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
	<meta http-equiv="pragma" content="no-cache" />
	<link rel="stylesheet" href="/css/style.css" type="text/css"/>
	<script type="text/javascript" src="/js/jquery.js"></script>
	<script type="text/javascript" src="/js/util.js"></script>
</head>
<script type="text/javascript">
//////////////////////////////////////////////////////////////////////
////  email = "wenpin.qian@happyelements.com"                     ////
////  team = "Athene"                                             ////
////  warnings = "This is generated page,Do Not Modify!";         ////
////  tips = "Opera & IE not supported|Chrome & Safari sugguested"////
//////////////////////////////////////////////////////////////////////
window.returnValue=0;
var silver_bagId = null;
var getsilver_bagUrl = "/silver_bag/get/";
var editsilver_bagUrl = "/silver_bag/edit/";
var currentsilver_bag = null;
$(document).ready(function() {
	silver_bagId = window.dialogArguments;
	$.ajax({
		   type: "GET",
		   url: getsilver_bagUrl,
		   data: "silver_bagId=" + silver_bagId,
		   dataType: "json",
		   success: function(data) {
			   if(data.code > 0) {
				   var result = data.result;
				   $("#silver_bagId").val(result.silver_bagId);
				   $("#deployId").val(result.deployId);
				   $("#itemId").val(result.itemId);
				   $("#silvers").val(result.silvers);
				   				   
				   currentsilver_bag = result; 
				   listselectors();
				   window.returnValue=1;
			   }else {
				   errDialog(data.message);
			   }
		   }
	});
});

function listselectors() {
var getItemSelectorUrl = "/special/Item/getList/";
$.ajax({
		   type: "GET",
		   url: getItemSelectorUrl,
		   data: "",
		   dataType: "json",
		   success: function(data) {
			   if(data.code > 0) {
				   selectitemId(s2json(data.result));
			   }else {
				   errDialog(data.message);
			   }
		   }
	});
}

function editsilver_bag() {
	var silver_bagIdParam = "silver_bagId=" + silver_bagId;
	var itemIdValue = $("#itemId").val();
	
	var itemIdParam = "itemId=" + itemIdValue;
		
	var silversValue = $("#silvers").val();
	
	var silversParam = "silvers=" + silversValue;
			
	$.ajax({
		   type: "POST",
		   url: editsilver_bagUrl,
		   		   data:  silver_bagIdParam + '&' +  itemIdParam  +'&'+   silversParam  ,
		   dataType: "json",
		   success: function(data) {
			   if(data.code > 0) {
			   	   beforeWindowClose();
				   window.close();
			   }else {
				   errDialog(data.message);
			   }
		   }
	});
}

			function selectitemId(options) {
			var optionHTML = "";
			for(var i in options) {
				optionHTML = optionHTML + "<option value='"+ options[i][0] +"'>" + options[i][1] + "</option>\n";
			}
			$("#itemId").html(optionHTML);
			if(currentsilver_bag != undefined) {
				$("#itemId").val(currentsilver_bag.itemId);
			}
		}
	
			function addsilvers() {
			var silversstr = $("#silvers").val();
			var returnCallback = function(retvalue) {
				$('#silvers').val(retvalue);
			}
			openDialog("/pages/core/Array.html",["/pages/customer/SilverWeight.html",silversstr],"dialogWidth:600px;dialogHeight:600px;status:no;help:no;center:yes",returnCallback);
		}
	
function openResource(fieldname,dependfield) {
	var param = "";
	if(dependfield!="") {
		param = $("#" + dependfield).val()
		if(param == null || param == "") {
			alert("你先把【" + $("#lbl_" + dependfield).html() + "】填了再上传");
			return;
		}
	}
	resourceDialog("silver_bag",$("#" + fieldname).val(),param,function(result) {
		if(result != undefined && result != "") {
			$("#" + fieldname).val(result);
		}
	});
}

function beforeWindowClose() {
	if(window.returnCallback) {
		window.returnCallback(window.returnValue);
	}
	window.onbeforeunload = null;
	return true;
}

</script>
<body onunload="beforeWindowClose()">
	<div class="addarea">
	<form action="/silver_bag/add" method="post">
		<table>
			<tbody>
				<tr>
					<td>ID</td><td><input type="text" id="silver_bagId" name="silver_bagId" disabled/></td>
					<td>发布Id</td><td><input type="text" id="deployId" name="deployId" disabled/></td>
				</tr>
			</tbody>
		</table>
		<table>
			<tbody>				
					<tr>					<td>
						<label for="itemId" id="lbl_itemId">道具ID</label>
													<select id="itemId" name="itemId">
							</select>
											</td>
									
										<td>
						<label for="silvers" id="lbl_silvers">银币列表</label>
													<input type="text" id="silvers" name="silvers" value="[]" disabled/>
							<input type="button" value="..." onclick="addsilvers()"/>
											</td>
					</tr>							</tbody>
		</table>
		<input type="button" onclick="editsilver_bag()" value="修改"/>
	</form>
	</div>
</body>